#FROM mymaven:3.8.2 as builder
#WORKDIR /app
#ADD . .
##RUN mvn dependency:go-offline
#RUN mvn clean package -Dmaven.test.skip=true
#RUN cp target/*.jar app.jar
#
#FROM openjdk:11-jre-slim-buster
#MAINTAINER yuxiaofengkea@gmail.com
#ENV JAVA_OPTS=""
#ENV PARAMS=""
#EXPOSE 8080
#WORKDIR /app
#RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo 'Asia/Shanghai' > /etc/timezone && touch app.jar
#COPY --from=builder /app/app.jar app.jar
#ENTRYPOINT ["sh", "-c", "java -Djava.security.egd=file:/dev/./urandom $JAVA_OPTS -jar app.jar $PARAMS"]

# 指定基础镜像，这是分阶段构建的前期阶段
FROM openjdk:11-jre-slim-buster as builder
# 执行工作目录
WORKDIR application
# 配置参数
ARG JAR_FILE=target/*.jar
# 将编译构建得到的jar文件复制到镜像空间中
COPY ${JAR_FILE} application.jar
# 向外暴露端口
EXPOSE 8080
# 通过工具spring-boot-jarmode-layertools从application.jar中提取拆分后的构建结果
RUN java -Djarmode=layertools -jar application.jar extract

# 正式构建镜像
FROM openjdk:11-jre-slim-buster
WORKDIR application
RUN ls -al
# 前一阶段从jar中提取除了多个文件，这里分别执行COPY命令复制到镜像空间中，每次COPY都是一个layer
COPY --from=builder application/dependencies/ ./
COPY --from=builder application/spring-boot-loader/ ./
COPY --from=builder application/snapshot-dependencies/ ./
COPY --from=builder application/application/ ./

ENTRYPOINT ["java", "org.springframework.boot.loader.JarLauncher"]
